package com.cate.config;

import com.cate.interceptor.JWTokenAdminInterceptor;
import com.cate.interceptor.JWTokenUserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @CreateTime: 2023/6/28
 * @Author: <==lhd==>
 * @Description: 配置拦截器
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private JWTokenAdminInterceptor jwTokenAdminInterceptor;

    @Autowired
    private JWTokenUserInterceptor jwTokenUserInterceptor;

    /**
     * 配置swagger
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        // 替换UI界面添加
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录拦截器
        registry.addInterceptor(jwTokenAdminInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns(
                        "/admin/employee/login",
                        "/doc.html",
                        "/doc.html/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/**/api-docs"
                );

        registry.addInterceptor(jwTokenUserInterceptor)
                .addPathPatterns("/user/**")
                .excludePathPatterns(
                        "/user/user/login",
                        "/doc.html",
                        "/doc.html/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/**/api-docs"
                );
    }




}
